package com.xinggq.user.service.controller.feign;

import com.xinggq.common.CommonResult;
import com.xinggq.user.api.dto.VerifyPasswordRequest;
import com.xinggq.user.api.dto.VerifyPasswordResponse;
import com.xinggq.user.api.feign.UserAuthApi;
import com.xinggq.user.service.service.UserAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户认证控制器
 *
 * @author xinggq
 * @since 2025-10-20
 */
@Slf4j
@RestController
@RequestMapping("/api/user/auth")
@RequiredArgsConstructor
@Tag(name = "用户认证API", description = "提供用户认证相关接口")
public class UserAuthController implements UserAuthApi {

  private final UserAuthService userAuthService;

  /**
   * 验证用户密码
   *
   * @param request 验证请求
   * @return 验证结果
   */
  @Override
  @PostMapping("/verify-password")
  @Operation(summary = "验证用户密码", description = "验证用户名和密码是否匹配")
  public CommonResult<VerifyPasswordResponse> verifyPassword(
      @Valid @RequestBody VerifyPasswordRequest request) {
    log.info("接收到密码验证请求: {}", request.getUsername());
    VerifyPasswordResponse response = userAuthService.verifyPassword(request);
    return CommonResult.ok(response);
  }

}